package com.srt.util;

import cn.hutool.core.util.StrUtil;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class DateTimeUtil {
    public final static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

    public static LocalTime strToTime(String timeStr) {
        int pointLength = StrUtil.subAfter(timeStr.trim(), ".", true).length();
        StringBuilder patternStr = new StringBuilder("HH:mm:ss");
        for (int i = 0; i < (pointLength > 6 ? 6 : pointLength); i++) {
            if (i == 0) {
                patternStr.append(".");
            }
            patternStr.append("S");
        }
        return LocalTime.parse(timeStr.trim(), DateTimeFormatter.ofPattern(patternStr.toString()));
    }

    public static void main(String[] args) {
        System.out.println(strToTime("00:00:06.1234538").toString());
    }


}
